﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HtmlAgilityPack;
using System.Net;
namespace FormTBK.Function
{
    public partial class GetKeyFromGG : Form
    {
        public GetKeyFromGG()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {
                
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string cookie = this.tbCookies.Text.Trim();
            string postData = "7|1|105|https://adwords.google.com/o/Targeting/|B00556853A56EB6B0D9DE85734001668|_|invoke|w|2s7|2zq|2ry|2rz|1c|TiAction (Search.SearchInput.KEYWORD_IDEAS.NONE.bundles=1,defaulted=1.RelatedToKeyword)|dmGOxRrlZhWTquFg5qs1T1-Jo7c:1368918695980|2zg|2t2|2sc|2se|15|1d|1e|2w7|2u9|2z5|RelatedToKeyword(KEYWORD_INPUT)|TiImpression|ParameterInQuery|CountryTarget(COMMON_ADVANCED_OPTIONS)|LanguageTarget(COMMON_ADVANCED_OPTIONS)|DeviceType(KEYWORD_IDEAS_ADVANCED_OPTIONS)|IncludeAdultContent(KEYWORD_IDEAS_ADVANCED_OPTIONS)|KeywordMatchType(MATCH_TYPE_SELECTOR_PANEL)|2e0|17|AXIS-NONE|AXIS-CONCEPTS|BundleSamples|CampaignNavigator|CellTable|ConceptBundling|CreateAdGroups|CurrencyPicker|DefaultToConcepts|CuesEnglishUserPercentage|DownloadAllSuggestedAdGroupsSingleRequest|GeoPickerV2|IcsCaptchaMessage|KeywordIdeasVisualizations|LabelService|LoadNegativesFromCampaignAndAdgroup|MobileAppPlacements|OneBox|PersistPreferences|SavedAdGroups|CuesExternalEnglishUserPercentage|RedirectInternalUserPercentage|SeedKeywordsTable|trafficEstimatorSunset|urlBundles|AverageMonthlyTrafficWithAfs|ExportToDraftboard|StarredIdeasEditing|SuggestedBid|CttEnabledForAllUsers|RollingThunder|2dn|2wj|1qk|zh_CN|1sj|2fb|2ea|2w9|2eb|IDEA_TYPE|KEYWORD|AVERAGE_TARGETED_MONTHLY_SEARCHES|AD_SHARE|COMPETITION|EXTRACTED_FROM_WEBPAGE|GLOBAL_MONTHLY_SEARCHES|IDEA_IN_ADGROUP|NEGATIVE_KEYWORDS|SEARCH_SHARE|SUGGESTED_BID|TARGETED_MONTHLY_SEARCHES|2vj|2gf|2g5|2f7|2g0|2wg|2kd|中国|CN|2gm|2kf|中文\uff08简体\uff09|2gz|2vi|2wf|oq|or|{0}|CATEGORY_PRODUCTS_AND_SERVICES|KEYWORD_CATEGORY|2gi|1|2|3|4|1|5|5|6|eVXHuAAAA|23|7|1|8|0|9|A|10|2|BQTOkN|BDQeVl|11|12|13|8|14|15|16|-4|0|0|17|6|A|0|0|0|0|0|0|0|18|0|19|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|20|0|0|0|7|0|0|0|21|22|1|23|1|24|22|1|25|14|15|16|-4|0|0|-11|A|0|0|0|0|0|0|0|-12|-13|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|-14|0|0|7|0|0|0|21|22|1|26|1|24|-18|14|15|16|-4|0|0|-11|A|0|0|0|0|0|0|0|-12|-13|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|-14|0|0|7|0|0|0|21|22|1|27|1|24|-18|14|15|16|-4|0|0|-11|A|0|0|0|0|0|0|0|-12|-13|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|-14|0|0|7|0|0|0|21|22|1|28|1|24|-18|14|15|16|-4|0|0|-11|A|0|0|0|0|0|0|0|-12|-13|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|-14|0|0|7|0|0|0|21|22|1|29|1|24|-18|14|15|16|-4|0|0|-11|A|0|0|0|0|0|0|0|-12|-13|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|-14|0|0|7|0|0|0|21|22|1|30|1|24|-18|31|15|16|-4|0|0|-11|A|0|0|0|0|0|0|0|-12|-13|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|20|31|32|1|33|32|0|34|32|1|35|32|1|36|32|1|37|32|1|38|32|1|39|32|1|40|32|1|41|32|1|42|32|1|43|32|1|44|32|1|45|32|1|46|32|1|47|32|1|48|32|1|49|32|1|50|32|1|51|32|1|52|32|1|53|32|1|54|32|1|55|32|1|56|32|1|57|32|1|58|32|1|59|32|1|60|32|1|61|32|1|62|32|1|63|0|0|7|0|0|0|64|65|59|66|0|67|0|68|50|0|0|69|0|0|70|1|71|12|72|73|72|74|72|75|72|76|72|77|72|78|72|79|72|80|72|81|72|82|72|83|72|84|85|71|5|86|87|88|4|89|90|91|92|0|1|93|0|94|90|95|96|67|97|98|99|100|0|101|2|102|0|0|0|0|0|31|15|16|-4|0|0|-11|A|0|0|0|0|0|0|0|-12|-13|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|20|31|32|1|33|32|0|34|32|1|35|32|1|36|32|1|37|32|1|38|32|1|39|32|1|40|32|1|41|32|1|42|32|1|43|32|1|44|32|1|45|32|1|46|32|1|47|32|1|48|32|1|49|32|1|50|32|1|51|32|1|52|32|1|53|32|1|54|32|1|55|32|1|56|32|1|57|32|1|58|32|1|59|32|1|60|32|1|61|32|1|62|32|1|63|0|0|7|0|0|0|64|-86|-87|67|0|68|50|0|0|-89|70|0|71|12|-92|-93|-94|-95|-96|-97|-98|-99|-100|-101|-102|-103|71|3|72|103|-93|72|104|71|6|-106|-107|105|90|-119|-109|-112|97|-116|99|100|0|-119|102|0|0|0|0|0|";
            string keyword = this.tbKeyword.Text.Trim();
            HtmlWeb w = new HtmlWeb();
            w.OverrideEncoding = Encoding.UTF8;
            w.UseCookies = true;
            w.NeedParse = false;
            w.PostData = string.Format(postData,this.tbKeyword.Text.Trim());
            w.CookieStr = cookie.Replace(";", ",");
            w.PreRequest += req;
            HtmlAgilityPack.HtmlDocument d = w.Load("http://adwords.google.com/o/Targeting/g?__u=1128392037&__c=1347217677&currency=CNY", "post");
            string result = d.Text;
            this.tbResult.Text = result;
        }
        private bool req(System.Net.HttpWebRequest request)
        {
            request.AllowAutoRedirect = false;
            request.Headers.Add("Accept-Language", "zh-CN,zh;q=0.8");
            request.Headers.Add("Accept-Charset", "GBK,utf-8;q=0.7,*;q=0.3");
            request.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
            request.Headers.Add("Origin", "https://adwords.google.com");
            request.Headers.Add("X-GWT-Permutation","04B0A6C682E6231FCA7733063E0D6F99");
            request.Headers.Add("X-Chrome-Variations","CIO2yQEIh7bJAQigtskBCKa2yQEIp7bJAQiptskBCKy2yQEI9oPKAQ==");
            request.AutomaticDecompression = DecompressionMethods.GZip;
            request.Host = "adwords.google.com";
            request.Referer = "https://adwords.google.com/o/Targeting/Explorer?ideaRequestType=KEYWORD_IDEAS&__u=1128392037&__c=1347217677";
            request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31";
            request.ContentType="text/x-gwt-rpc; charset=UTF-8";
            return true;
        }

        private void tbResult_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
